 
layui.define(['admin','transfer'], function(exports){

  var $ = layui.$
  ,transfer = layui.transfer
  ,setter = layui.setter
  ,admin = layui.admin;
  var roleId = $('#roleId').val();
  var userIds = [];
  admin.req({
	        url: layui.setter.host+'/adminmanager/role/queryPermissionPerson'
	        ,type:'post'
	        ,dataType:'json'
	        ,contentType: "application/json; charset=utf-8"
	        ,data:'{"roleId":"'+roleId+'"}'
	        ,done: function(resData){
	          //请求成功后
//console.log('/////////');
//					console.log(resData.data);
//					console.log('/////////');
	        	if(resData.status == setter.response.statusCode.status_Success){
	        		transfer.render({
	        	  	    elem: '#operationPerson'
	        	  	    ,title:['用户列表','选中人员']
	        	  		,showSearch:true
	        	  		,text: {
	        	  		  none: '无数据' 
	        	  			  ,searchNone: '无匹配数据' 
	        	  			}
	        	    	,parseData: function(res){
	        	    	      return {
	        	    	          "value": res.userId //数据值
	        	    	          ,"title": res.name+"("+res.phone+")" //数据标题
	        	    	        }
	        	    	      }
	        	  	    ,data: resData.data
	        	  	    ,onchange: function(obj, index){
	        	  	      //var arr = ['左边', '右边'];
	        	  	      //layer.alert('来自 <strong>'+ arr[index] + '</strong> 的数据：'+ JSON.stringify(obj)); //获得被穿梭时的数据
	        	  	      if(index==0){
	        	  	    	  layui.each(obj,function(inx,val){
	        	  	    		userIds.push(val.value);
	        	  	    	  })
	        	  	      }else{
	        	  	    	layui.each(obj,function(inx,val){
	        	  	    		userIds.remove(val.value);
	        	  	    	  })
	        	  	      }
	        	  	      $('#userId').val(JSON.stringify(userIds));
	        	  	    }
	        	  	  })
	        	}else{
	        	  layer.msg(resData.msg);
	        	}
	        }
	      });
  Array.prototype.indexOf = function(val) {
  	for (var i = 0; i < this.length; i++) {
  	if (this[i] == val) return i;
  	}
  	return -1;
  	};
  	
 	Array.prototype.remove = function(val) {
 		var index = this.indexOf(val);
 		if (index > -1) {
 		this.splice(index, 1);
 		}
 		};
  
  //对外暴露的接口
  exports('roleTransfor', {});
});